<!DOCTYPE html>
<html>
<head>
    <include file="public/public_css" />

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <include file="public/header-min" />
    <!-- Left side column. contains the logo and sidebar -->
    <include file="public/left" />
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
               菜单管理
                <a href="javascript:void(0);" onclick="addMenu();"><button type="button" class="btn btn-primary">添加菜单</button></a>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li class="active">菜单管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Small boxes (Stat box) -->
            <!-- Small boxes (Stat box) -->
            <div class="row">
                <table id="menuList" class="table table-hover">
                    <tr>
                        <th>排序</th>
                        <th>id</th>
                        <th>菜单名称</th>
                        <th>控制器</th>
                        <th>操作方法</th>
                        <th>菜单等级</th>
                        <th>显示</th>
                        <th>操作</th>
                    </tr>
                    <volist name="list" id="vo">
                       <tr  <if condition="$vo.menu_level == 1">class="danger"</if>>
                               <td>
                                   <input type="text" class="list-order" data-menu_id="{$vo.menu_id}" name="list_order" value="{$vo.list_order}">
                               </td>
                               <td>{$vo.menu_id}</td>
                               <td>{$vo._name}</td>
                               <td>{$vo.menu_con}</td>
                               <td>{$vo.menu_act}</td>
                               <td>{$vo.menu_level}</td>
                               <td class="is-show-td">
                                   <i  data-menu_id="{$vo.menu_id}" data-is_show="{$vo.is_show}" class="is-show ion-checkmark-circled <if condition="$vo.is_show == 1">is-show1</if>"></if>
                               </td>
                               <td>
                                   <a class="delMenu" data-menu_id="{$vo.menu_id}" href="javascript:void(0);" >

                                       <button type="button" class="btn btn-danger">删除</button>
                                   </a> |
                                   <a class="editMenu" data-menu_id="{$vo.menu_id}" href="javascript:void(0);">
                                       <button type="button" class="btn btn-info">修改</button>
                                   </a>
                               </td>
                       </tr>
                    </volist>
                </table>

            </div>

            <div>
                <button id="listOrder"  type="button" class="btn btn-info" >排序</button>
            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <include file="public/footer" />

    <!-- Control Sidebar -->

    <!-- /.control-sidebar -->
    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<include file="public/public_js" />

<script>
        //添加菜单
    function addMenu(){
        layer.open({
            type: 2,
            area: ['750px', '550px'],
            fixed: false, //不固定
            maxmin: true,
            content: '{$Think.WEB_PATH}/Admin/Menu/addMenu'
        });
    }
      //修改菜单
       $('.editMenu').click(function(){
           var menu_id = $(this).data('menu_id');
           layer.open({
               type: 2,
               area: ['900px', '650px'],
               fixed: false, //不固定
               maxmin: true,
               content: '{$Think.WEB_PATH}/Admin/Menu/editMenu?menu_id='+menu_id
           });
       });
        //删除菜单
    $('.delMenu').click(function(){
        var menu_id = $(this).data('menu_id');
        layer.open({
            btn: ['删除', '取消'],
            yes: function(){
                $.ajax({
                    type : 'POST', //GET,POST
                    url: '{$Think.WEB_PATH}/Admin/Menu/delMenu?menu_id='+ menu_id,
                    dataType : 'json', //xml,json,script，默认为null
                    success : function (data) {
                        layer.open({
                            type: 1,
                            time: 1000,
                            area: ['200px', '200px'],
                            content: data.msg //服务器返回的消息
                        });
                        setTimeout(function(){
                            window.location.reload();
                        },1200);
                    },
                    error : function (event, errorText, errorType) { //错误时调用
                        alert(errorText + errorType);
                    }
                })
            },
            no: function(){

            },
            fixed: false, //不固定
            maxmin: true,
            content:'确定要删除吗？'
        });
    });
               //排序
           var  list_order = [];
        $("input[name='list_order']").change(function(){
            list_order[$(this).data('menu_id')] = $(this).val();
        });
        $('#listOrder').click(function(){
            list_order = $.toJSON(list_order); //格式化JS数组，将其转化为JSON格式发送到服务
            $.ajax({
                type: 'POST', //GET,POST
                url: '{$Think.WEB_PATH}/Admin/Menu/orderMenu',
                data:{list_order:list_order},
                dataType: 'json', //xml,json,script，默认为null
                success: function (data) {
                    layer.open({
                        type: 1,
                        time: 5000,
                        area: ['200px', '200px'],
                        content: data.msg //服务器返回的消息
                    });

                    setTimeout(function () {
                        window.location.reload();
                    }, 1200);
                },
                error: function (event, errorText, errorType) { //错误时调用
                    alert(errorText + errorType);
                }
            })
        });

              //显示与不显示
        $('.is-show').click(function(){
            var menu_id = $(this).data('menu_id');
            var is_show = $(this).data('is_show');
            var isShow = $(this);
            $.ajax({
                type: 'POST',
                url:"{$Think.WEB_PATH}/Admin/Menu/isShowMenu?menu_id=" + menu_id + "&is_show=" + is_show,
                dataType:'json',
                success:function(data){
                    if(data.status){
                        if(isShow.hasClass("is-show1")){
                            isShow.removeClass("is-show1");
                            isShow.data('is_show', 0);
                        }else{
                            isShow.addClass("is-show1");
                            isShow.data('is_show', 1);
                        }
                    }
                }

            });
        });
</script>
</body>
</html>
